package com.lvcoding.auth2.auth.shizhan.verifycode.sms;

import com.lvcoding.auth2.auth.shizhan.verifycode.parent.AbstractVerifyCodeHandler;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 短信验证码
 *
 * @author wuyanshen
 */
@RequiredArgsConstructor
@Component
public class SmsVerifyCodeHandler extends AbstractVerifyCodeHandler<SmsCode> {

    private final SmsCodeSender smsCodeSender;

    @Override
    public void sendCode(ServletWebRequest servletWebRequest, SmsCode smsCode) throws Exception {
        String code = smsCode.getCode();
        String phone = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "mobile");
        smsCodeSender.send(phone, code);
    }
}
